(function(window){
	function Lyric(path){
		return new Lyric.prototype.init(path);
	}
	Lyric.prototype={
		constructor: Lyric,
		musicList:[],
		init:function(path){
		this.path=path;
		},
		times:[],//保存所有时间
		lyrics:[],//保存所有歌词
		index:-1,
	      loadLyric : function(callBack){
			var $this=this;
			$.ajax({
			url:$this.path,
			dataType:"text",
			success:function(data){
//            console.log(data);
            $this.parseLyric(data);
            callBack();
			},
			error:function(e){
				console.log(e);
			}
		});
		},
		parseLyric:function(data){
			var $this=this;
			
			//注意一定要清空上一曲的歌词和时间
			$this.times=[];
			$this.lyrics=[];
			var array=data.split("\n");
			//[03:21.31]打印出来是这样的
			var timeReg=/\[(\d*:\d*\.\d*)\]/
          //遍历取出所有的歌词
         $.each(array,function(index,ele){
         	//处理歌词
         	var lrc=ele.split("]")[1];
         	//排除空字符串()
         	if(lrc.length==1||lrc.length==0) return true;
         	$this.lyrics.push(lrc);
         
         
            var res=timeReg.exec(ele);
         	if(res==null)return true;//去除空的那些歌词
         	var timeStr=res[1];//03:21.31打印出这个时间
         	var res2=timeStr.split(":");
         	var min=parseInt(res2[0])*60;
         	var sec=parseFloat(res2[1]);
         	var time=parseFloat(Number(min+sec).toFixed(2))
         	$this.times.push(time);
         })
//			console.log($this.times);
//			console.log($this.lyrics);
		},
	    currentIndex:function(currentTime){
//	    	console.log(currentTime);
            if(currentTime>=this.times[0]){
            	this.index++;
            	this.times.shift();//shift方法是删除数组最前面的元素
            }
            return this.index;
	    },
	}
	Lyric.prototype.init.prototype = Lyric.prototype;
	window.Lyric=Lyric;
})(window);